<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ApiController
 *
 * @author wangnaixin
 */

namespace Api\Controller;
use Think\Controller;

class ApiController extends Controller {

    //定义返回状态码
    public $EMPTY_CODE = 300;
    public $ERROR_CODE = -100;
    public $SUCCESS_CODE = 200;
    public $white_list = ['Login','House','Public','Common'];

    function __construct() {
        parent::__construct();
        $this->checkUser();
    }

    function _empty(){
        return $this->response('非法请求！',1);
    }

    public function callBack($msg,$code=200,$data=[]){
        $result = array(
            'msg'=>$msg,
            'code'=>$code,
            'data'=>$data
        );
        if (session('returnArray')) {
        	return $result;
        }
        if(IS_AJAX || I('ajax') == 1){
            $this->ajaxReturn($result);
        }else{
            if($code == $this->SUCCESS_CODE){
                return $data;
            }else{
                return false;
            }
        }
        
        
        
    }
    
    public function response($msg,$code=0,$data=array()){
    	$result = array(
    		'msg' => $msg,
    		'code' => $code,
    		'data' => $data
    	);
    	if (session('returnArray')) {
    		return $result;
    	}
    	if (IS_AJAX || I('ajax') == 1) {
    		$this->ajaxReturn($result);
    	}
    	return $result;
    }
    
    

    /**
     * 判断用户是否真实合法
     */
    private function checkUser(){
        if(!in_array(MODULE_NAME, $this->white_list)){
            //判断用户是否带有身份标示  根据身份标示 获取用户基本信息
        }
    }
}
